package com.huizu.goods.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huizu.common.annotation.Log;
import com.huizu.common.enums.BusinessType;
import com.huizu.goods.domain.ShopRotation;
import com.huizu.goods.service.IShopRotationService;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.common.core.page.TableDataInfo;

/**
 * 轮播图Controller
 * 
 * @author 
 * @date 2022-02-07
 */
@Controller
@RequestMapping("/shop/rotation")
public class ShopRotationController extends BaseController
{
    private String prefix = "shop/rotation";

    @Autowired
    private IShopRotationService shopRotationService;

    @RequiresPermissions("shop:rotation:view")
    @GetMapping()
    public String rotation()
    {
        return prefix + "/rotation";
    }

    /**
     * 查询轮播图列表
     */
    @RequiresPermissions("shop:rotation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopRotation shopRotation)
    {
        startPage();
        List<ShopRotation> list = shopRotationService.selectShopRotationList(shopRotation);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @RequiresPermissions("shop:rotation:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopRotation shopRotation)
    {
        List<ShopRotation> list = shopRotationService.selectShopRotationList(shopRotation);
        ExcelUtil<ShopRotation> util = new ExcelUtil<ShopRotation>(ShopRotation.class);
        return util.exportExcel(list, "轮播图数据");
    }

    /**
     * 新增轮播图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮播图
     */
    @RequiresPermissions("shop:rotation:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopRotation shopRotation)
    {
        return toAjax(shopRotationService.insertShopRotation(shopRotation));
    }

    /**
     * 修改轮播图
     */
    @RequiresPermissions("shop:rotation:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShopRotation shopRotation = shopRotationService.selectShopRotationById(id);
        mmap.put("shopRotation", shopRotation);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮播图
     */
    @RequiresPermissions("shop:rotation:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopRotation shopRotation)
    {
        return toAjax(shopRotationService.updateShopRotation(shopRotation));
    }

    /**
     * 删除轮播图
     */
    @RequiresPermissions("shop:rotation:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopRotationService.deleteShopRotationByIds(ids));
    }
}
